// 排行榜相关类型定义

export interface LeaderboardEntry {
  userId: string;
  score: number;
  rank: number;
  metadata: Record<string, any> | undefined;
  updatedAt: Date;
}

export interface LeaderboardConfig {
  maxEntries?: number;
  scoreType: 'highest' | 'lowest';
  updateStrategy: 'replace' | 'increment' | 'max' | 'min';
  timeWindow?: TimeWindow;
  archiveOldEntries?: boolean;
}

export interface TimeWindow {
  type: 'daily' | 'weekly' | 'monthly' | 'yearly' | 'custom';
  duration?: number; // for custom type, in seconds
  timezone?: string;
}

export interface LeaderboardStats {
  totalEntries: number;
  averageScore: number;
  medianScore: number;
  topScore: number;
  bottomScore: number;
  lastUpdated: Date;
  updateFrequency: {
    perMinute: number;
    perHour: number;
    perDay: number;
  };
}

export interface LeaderboardQuery {
  start?: number;
  end?: number;
  around?: string; // userId
  range?: number;
  includeMetadata?: boolean;
  includeScores?: boolean;
}

export interface LeaderboardResult {
  entries: LeaderboardEntry[];
  totalCount: number;
  userRank: number | undefined;
  userScore: number | undefined;
  hasMore: boolean;
}

export interface ScoreUpdate {
  userId: string;
  score: number;
  metadata?: Record<string, any>;
  timestamp?: Date;
}

export interface LeaderboardArchive {
  period: string; // e.g., "2023-12-01" for daily
  entries: LeaderboardEntry[];
  stats: LeaderboardStats;
  archivedAt: Date;
}

export interface RankChange {
  userId: string;
  previousRank?: number;
  currentRank: number;
  rankChange: number;
  scoreChange: number;
  timestamp: Date;
}
